package vn.co.thn.android.store.fragment;

import java.util.ArrayList;

import com.android.volley.VolleyError;

import vn.co.thn.android.store.NSUrlApi;
import vn.co.thn.android.store.R;
import vn.co.thn.android.store.adapter.NSNewFeedListAdapter;
import vn.co.thn.android.store.data.NSNewFeedListData;
import vn.co.thn.android.store.util.NSRequestService;
import vn.co.thn.android.store.util.NSRequestService.NSRequestServiceCAllBack;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class NSNewFeedFragment extends NSCommonFragment {
	private ListView lst;
	private NSNewFeedListAdapter adapter;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.ns_new_feed_list_fragment, container, false);
		lst = (ListView) view.findViewById(R.id.lst);
		return view;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		getData();
	}

	private void getData() {
		NSRequestService requestService = new NSRequestService(NSUrlApi.Api_NewFeed_List, NSNewFeedListData.class,
				new NSRequestServiceCAllBack<NSNewFeedListData>() {

					@Override
					public void onResult(NSNewFeedListData data, boolean isUpdate) {
						// TODO Auto-generated method stub
						if (adapter == null) {
							adapter = new NSNewFeedListAdapter(getActivity(), data.getList_newfeed());
							lst.setAdapter(adapter);
						} else {
							adapter.notifyDataSetChanged();
						}
					}

					@Override
					public void onResult(ArrayList<NSNewFeedListData> data, boolean isUpdate) {
						// TODO Auto-generated method stub

					}

					@Override
					public void onError(VolleyError error) {
						// TODO Auto-generated method stub

					}

					@Override
					public void onException(Exception e) {
						// TODO Auto-generated method stub

					}
				},this);
		requestService.StartPost();
	}
}
